using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestEnemy : MonoBehaviour
{
    public float maxHp = 15;
    public float Hp;

    public GameObject[] HpBanner;

    public DynamicColl dynamicColl;
    public int action;

    void Start()
    {
        Hp = maxHp;
        dynamicColl = this.GetComponent<DynamicColl>();
    }

    void FixedUpdate()
    {
        float deltaTime = Time.deltaTime;
        dynamicColl.speed.y -= dynamicColl.gravity * deltaTime;

        if (Hp <= 0)
        {
            Dead();
        }

        for(int i = 2; i > Hp / maxHp * 3-1; i--)
        {
            HpBanner[i].SetActive(false);
        }


        action = Random.Range((int)(-10f - dynamicColl.speed.x*2), (int)(10f - dynamicColl.speed.x*2));
        dynamicColl.speed.x += action * deltaTime;
        if (action == 0 && dynamicColl.model == 0) dynamicColl.speed.y = Random.Range(5, 10);
    }

    public void Dead()
    {
        Destroy(this.gameObject);
    }
}
